var http = require('../../utils/http.js')
var app = getApp();

Page({

    /**
     * 页面的初始数据
     */
    data: {

    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData({
            typeid: options.typeid
        })
        this.init();
    },
    init:function(){
        var that = this;
        http.httppost('InventoryData/FindDoubleItems?typeid=' + that.data.typeid, {}, function (res) {
            wx.hideToast();
            var typeidarr = [], itemArr = [];

            res.map(item => {
                typeidarr.push(item.ItemID);
            })
            typeidarr = Array.from(new Set(typeidarr));

            typeidarr.map(mm => {
                var arrObj = { list:[],whs:[],status:0};
                res.map(nn => {
                    if (nn.ItemID == mm) {
                        
                        arrObj.list.push(nn);
                        arrObj.whs.push(nn.Wh);
                    }
                })
                itemArr.push(arrObj);
            })
            that.setData({
                list: itemArr
            })
            console.log(that.data.list)
        }, 'GET')
    },
    selectAcction:function(e){
        var that = this;
        // e.currentTarget.dataset.index
        // e.currentTarget.dataset.itemid
        // e.currentTarget.dataset.wh
        console.log(e)
        wx.showModal({
            title: '',
            content: "全部归到" + that.data.list[e.currentTarget.dataset.index].whs[e.detail.value]+"仓位",
            success:function(res){
                if (res.confirm) {
                    http.httppostmore('InventoryData/SaveGuidang', { itemid: e.currentTarget.dataset.itemid, whdes: that.data.list[e.currentTarget.dataset.index].whs[e.detail.value]},function(temp){
                        that.data.list[e.currentTarget.dataset.index].status = 1;
                        that.setData({
                            list: that.data.list
                        })
                        wx.hideToast();
                        wx.showModal({
                            title: '',
                            showCancel:false,
                            content: temp.Message
                        })
                    })
                } else{
                   
                }
            }
        })
    }
    
})